package com.A1908.service.impl;

import com.A1908.dao.AttendPeopleInfoDao;
import com.A1908.dao.impl.AttendPeopleInfoDaoImpl;
import com.A1908.entity.*;
import com.A1908.service.AttendPeopleInfoService;
import com.A1908.service.RelationService;

import java.util.List;

public class AttendPeopleServiceImpl implements AttendPeopleInfoService {
    AttendPeopleInfoDao attendPeopleInfoDao = new AttendPeopleInfoDaoImpl();
    RelationService relationService = new RelationServiceImpl();

    @Override
    public List<AttendPeopleInfo> getAllAttendPeopleInfo(User user) {
        return attendPeopleInfoDao.getAllAttendPeopleInfo(user);
    }

    @Override
    public int addAttendPeople(AttendPeopleInfo attendPeopleInfo) {
        return attendPeopleInfoDao.addAttendPeople(attendPeopleInfo);
    }

    @Override
    public int delAttendPeople(AttendPeopleInfo attendPeopleInfo) {
        return attendPeopleInfoDao.delAttendPeople(attendPeopleInfo);
    }

    @Override
    public int editAttendPeople(AttendPeopleInfo attendPeopleInfo) {
        return attendPeopleInfoDao.editAttendPeople(attendPeopleInfo);
    }

    @Override
    public List<AttendPeopleInfo> getAllAttendPeopleInfo(User user, PageEntity pageEntity) {
        List<AttendPeopleInfo> list = attendPeopleInfoDao.getAllAttendPeopleInfo(user, pageEntity);
        pageEntity.setTotalCount(attendPeopleInfoDao.getCount(user));
        if (pageEntity.getTotalCount() % pageEntity.getPageSize() == 0) {
            pageEntity.setTotalPage(pageEntity.getTotalCount() / pageEntity.getPageSize());
        } else {
            pageEntity.setTotalPage((pageEntity.getTotalCount() / pageEntity.getPageSize()) + 1);
        }
        pageEntity.setInfo(list);
        return list;
    }

    @Override
    public List<AttendPeopleInfo> findAttendPeopleInfoByFeast(FeastInfo feastInfo) {
        return attendPeopleInfoDao.getAttendPeopleInfoByFeast(feastInfo);
    }

    @Override
    public double totalGift(FeastInfo feastInfo) {
        return attendPeopleInfoDao.getTotalGiftByByFeast(feastInfo);
    }

    @Override
    public int CellEdit(int id, String field, String value) {
        return attendPeopleInfoDao.editSingleValue(id,field,value);
    }
}
